<template>
	<video-player class="vjs-custom-skin" ref="videoPlayer" :options="playerOptions" :playsinline="true"> </video-player>
</template>

<script>
//普通的视频播放
import 'video.js/dist/video-js.css';
import 'vue-video-player/src/custom-theme.css';
import { videoPlayer } from 'vue-video-player';
export default {
	components: {
		videoPlayer,
	},
	data() {
		return {};
	},
	mounted() {
		console.log('this is current player instance object', this.player);
	},
	computed: {
		player() {
			return this.$refs.videoPlayer.player;
		},
		playerOptions() {
			return {
				playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
				autoplay: false, //如果true,浏览器准备好时开始回放。
				muted: false, // 默认情况下将会消除任何音频。
				loop: false, // 导致视频一结束就重新开始。
				preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
				language: 'zh-CN',
				aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
				fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
				sources: [],
				poster:
					'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1589803805919&di=2e02eab8e996a46b7accb506d1aa5abd&imgtype=0&src=http%3A%2F%2Fhbimg.b0.upaiyun.com%2F99d3b0ec3075bc5ce14f78351e465b4720392374246c3-KXGdj2_fw658', //你的封面地址
				notSupportedMessage: '此视频暂无法播放，请稍后再试', //允许覆盖Video.js无法播放媒体源时显示的默认信息。
				controlBar: {
					timeDivider: true,
					durationDisplay: true,
					remainingTimeDisplay: false,
					fullscreenToggle: true, //全屏按钮
				},
			};
		},
	},
	methods: {
		// listen event
		onPlayerPlay(player) {
			console.log('player play!', player);
		},
		onPlayerPause(player) {
			console.log('player pause!', player);
		},
		// ...player event

		// or listen state event
		playerStateChanged(playerCurrentState) {
			console.log('player current update state', playerCurrentState);
		},

		// player is ready
		playerReadied(player) {
			console.log('the player is readied', player);
			// you can use it to do something...
			// player.[methods]
		},
	},
};
</script>
<style lang="scss" scoped></style>
